package com.lambda;


import com.lambda.service.impl.MyInterfaceImpl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


public class Lambda02 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("zhasdna");
        list.add("lisi");
        list.add("wangwu");
        list.add("zhaoliu");
        //对集合排序
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        System.out.println(list);

        //使用Lambda表达式写
        Collections.sort(list, (String o1, String o2) -> {
            return o1.compareTo(o2);
        });
        System.out.println(list);

        //简化写法
        Collections.sort(list, (o1,o2) -> o1.compareTo(o2));
        System.out.println(list);


        //简化写法
        //类::方法 引用类中的实例方法
        Collections.sort(list, String::compareTo);
        System.out.println(list);
    }
}
